home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / dxlib50.zip / MICROSOF.ZIP / EASYXEX2.C < prev    next >
C/C++ Source or Header  |  1995-02-11  |  3KB  |  84 lines

  1. /*This is the second example program in EASYX.DOC.  The program is written
  2. for Microsoft C.  The program should be linked with EASYX.LIB.  Borland C
  3. users must change the second line below to:  #include <easyxb.h>, and should
  4. link with EASYXB.LIB.*/
  5.  
  6. #include<stdio.h>
  7. #include <string.h>
  8. #include <easyx.h>
  9.  
  10. void main (void)
  11. {
  12.   int i;
  13.   unsigned long errcode, nobytes, xaddress, xsize, handle, arrayaddress;
  14.   int array[100];
  15.   struct xfile fb;                 /*Declare file control block*/
  16.  
  17.   errcode = INITXLIB();            /*Initialize XLIB*/
  18.   if(errcode != 0)
  19.   {
  20.     printf("Library initialization error:  %lX\n",errcode);
  21.     return;
  22.   }
  23.  
  24.   nobytes = 0x10000;               /*Allocate 64k of extended memory*/
  25.   errcode = XMALLOC(nobytes,&xaddress,&xsize,&handle);
  26.   if(errcode != 0)
  27.   {
  28.     printf("Extended memory allocation error:  %lX\n",errcode);
  29.     return;
  30.   }
  31.  
  32.   for(i = 0; i < 100; i++)         /*Put something in array[]*/
  33.     array[i] = i;
  34.  
  35.   arrayaddress = LINADR(array);    /*Compute linear address of array[]*/
  36.  
  37.   fb.condcode = 0;                 /*Set control block to create file*/
  38.   strcpy(fb.fname,"junk.dat");     /*Specify file name*/
  39.   fb.blkadr = arrayaddress;        /*Will transfer array[] to the file*/
  40.   fb.blksize = 200;                /*There are 200 bytes in array[]*/
  41.   fb.bufsize = 0;                  /*Force XLIB to use its internal buffer*/
  42.   XFSAVE(&fb);                     /*Create file and save array[] to it*/
  43.   if(fb.condcode != 0)
  44.   {
  45.     printf("File save error:  %lX\n",fb.condcode);
  46.     return;
  47.   }
  48.  
  49.   XFOPEN(&fb);                     /*Reopen the file*/
  50.   if(fb.condcode != 0)
  51.   {
  52.     printf("File open error:  %lX\n",fb.condcode);
  53.     return;
  54.   }
  55.  
  56.   fb.blkadr = xaddress;         /*Prepare to transfer the file to extended*/
  57.   fb.blksize = 100;             /*Will transfer only 100 bytes*/
  58.   fb.fptrmode = 0;              /*File pointer is relative to start of file*/
  59.   fb.fptr = 100;                /*Set file pointer to 50th element*/
  60.   XFREAD(&fb);                  /*Read last 50 elements to extended*/
  61.   if(fb.condcode != 0)
  62.   {
  63.     printf("File read error:  %lX\n",fb.condcode);
  64.     return;
  65.   }
  66.  
  67.   MOVMEM(arrayaddress,xaddress,100); /*Transfer file contents back to array[]
  68.  
  69.  
  70.   XFCLOSE(&fb);                      /*Close the file*/
  71.   if(fb.condcode != 0)
  72.   {
  73.     printf("File close error:  %lX\n",fb.condcode);
  74.     return;
  75.   }
  76.  
  77.   errcode = XFREE(handle);           /*Release extended memory*/
  78.   if(errcode != 0)
  79.   {
  80.     printf("Memory release error:  %lX\n",errcode);
  81.     return;
  82.   }
  83. }
  84.